using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Net.SourceForge.WURFL.Core;
using Common;

namespace Roaming.controls
{
    public partial class IncHeader : System.Web.UI.UserControl
    {
        protected int cols = 3;
        protected string bannerUrl = "";
        protected string strSize = "320";
        protected string linkUrl = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            string strUA = Request.Headers["USER-AGENT"].ToString();
            if (strUA.ToLower().Contains("opera"))
            {
                if (Request.Headers["X-OperaMini-Phone-UA"] != null)
                    strUA = Request.Headers["X-OperaMini-Phone-UA"].ToString();
            }
            strSize = DAL.getSizePage(Request.Headers["USER-AGENT"].ToString());
            cols = DAL.getColLinkSite(strUA);
            if (cols > 3)
            {
                cols = 3;
            }
            string tmp = getBannerUrl(strSize);

            if (!string.IsNullOrEmpty(tmp))
            {
                string url = ConfigurationManager.AppSettings["ImageUrl"]+tmp;
                if (!string.IsNullOrEmpty(linkUrl))
                {
                    bannerUrl = "<a href=" + linkUrl + "><img src='" + url + "' border='0'/></a>";                   
                }
                else
                    bannerUrl = "<img src='" + url + "' border='0'/></a>";
            }

        }
        protected string getBannerUrl(string size)
        {
            DataSet ds = DAL.GetDataSet("exec tblBanner_GetActive");
            if (ds != null && ds.Tables[0].Rows.Count > 0)
            {
                linkUrl = ds.Tables[0].Rows[0]["linkUrl"].ToString();
                //forwardMsisdn = ds.Tables[0].Rows[0]["isForward"].ToString();

                return ds.Tables[0].Rows[0]["img" + size].ToString();
            }
            else
                return "";
        }
    }
}